<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\wh\model;

use think\Model;
use app\admin\model\Config as ConfigModel;
use think\Db;

/**
 * 供应商模型
 */
class Supplier extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'wh_supplier';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 获取分组
     * @param int $pid 父ID
     * @param int $type_pid 类型ID
     * @param string $field 字段
     * @return array
     */
    public static function getGroup($pid = 0,$type_pid = 0,$field = 'title')
    {
        $map['status'] = 1;
        $map['pid'] = $pid;
        $map = "status = 1 and pid = {$pid}";
        if(!empty($type_pid))$map .= " and find_in_set({$type_pid},`type_pid`)";
        $menus = self::where($map)->order('sort,id')->column($field,'id');
        return $menus;
    }

    /**
     * 根据分组获取子分组
     * @param int $pid 父ID
     * @param bool|string $fields 要返回的字段
     * @param array $map 查找条件
     * @return array
     */
    public static function getMenusByGroup($pid = 0, $fields = true, $map = [])
    {
        $map['pid'] = $pid;
        return self::where($map)->order('sort,id')->column($fields, 'id');
    }

}
